Imports System
Imports System.Data
Imports System.Configuration
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls

Partial Public Class wucHeader
    Inherits System.Web.UI.UserControl

    Private _Usuario As Usuario

    Protected Sub Page_Load(ByVal sender As System.Object, ByVal e As EventArgs) Handles Me.Load

        Try

            If Not Session("Usuario") Is Nothing Then
                _Usuario = CType(Session("Usuario"), Usuario)
                Me.ltrNomeUsuario.Text = _Usuario.Nome
                Me.hypAdministration.Visible = _Usuario.Administrador
                Me.ltrBarra.Visible = _Usuario.Administrador
            End If

        Catch ex As Exception

            Session.Clear()
            Response.Redirect("~/login.aspx")

        End Try

    End Sub

    Protected Sub hypLogOut_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles hypLogOut.Click

        Try

            Session.Clear()
            Response.Redirect("~/login.aspx")

        Catch ex As Exception

            Session.Clear()
            Response.Redirect("~/login.aspx")

        End Try

    End Sub

    Protected Sub btnBuscar_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnBuscar.Click

        If Not Me.txtBusca.Text.Trim.Equals(String.Empty) Then
            Response.Redirect(String.Concat("~/search_result.aspx?Search=", Me.txtBusca.Text.Trim))
        End If

    End Sub

    Protected Sub hypAdministration_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles hypAdministration.Click

        Response.Redirect("~/admin/default.aspx")

    End Sub

    Protected Sub hypMyAccount_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles hypMyAccount.Click

        Response.Redirect(String.Concat("~/minha_conta.aspx?UsuarioID=", _Usuario.UsuarioID.ToString))

    End Sub

    Protected Sub imgLogotipo_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles imgLogotipo.Click

        Response.Redirect("~/default.aspx")

    End Sub

End Class